package ioc07;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/**
 * Author：汤小洋
 * Date：2023-12-13 17:03
 * Description：<描述>
 */
// @Component("springBean")
@Component
@Lazy
@Scope("prototype")
public class SpringBean {

    @Value("${name}")
    private String name;

    @Value("${age}")
    private int age;

    @Override
    public String toString() {
        return "SpringBean{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    // 相当于init-method
    @PostConstruct
    public void init() {
        System.out.println("SpringBean.init()");
    }

    // 相当于destroy-method
    @PreDestroy
    public void destroy() {
        System.out.println("SpringBean.destroy()");
    }
}
